#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;


class Solution {
public:
    int furthestDistanceFromOrigin(string moves) {
        int gps = 0;
        sort(moves.begin(), moves.end());
        for (auto& e : moves)
        {
            if (e == 'L')
                --gps;
            else if (e == 'R')
                ++gps;
            else
            {
                gps += (abs(gps + 1) > abs(gps)) ? 1 : -1;
            }
        }

        return abs(gps);
    }
};

int main()
{
    Solution().furthestDistanceFromOrigin("_R__LL_");


    return 0;
}